Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
    ''' <summary>
    ''' Controller class for Topics
    ''' </summary>
		<System.ComponentModel.DataObject()> Public Partial Class TopicsController
    
        ' Preload our schema..
        Dim thisSchemaLoad As Topics = New Topics()
        Private strUserName As String = String.Empty
        Protected ReadOnly Property UserName() As String
            Get
				If strUserName.Length = 0 Then
		        
    				If Not System.Web.HttpContext.Current Is Nothing Then
						strUserName = System.Web.HttpContext.Current.User.Identity.Name
					Else
		        		strUserName = System.Threading.Thread.CurrentPrincipal.Identity.Name
					End If
					Return strUserName
				End If
				Return strUserName
			End Get
        End Property
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchAll() As TopicsCollection
        
            Dim coll As TopicsCollection = New TopicsCollection()
            Dim qry As Query = New Query(Topics.Schema)
            coll.LoadAndCloseReader(qry.ExecuteReader())
            Return coll
            
        End Function
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchByID(ByVal Topicid As Object) As TopicsCollection 
        
            Dim coll As TopicsCollection = New TopicsCollection().Where("topicid", Topicid).Load()
            Return coll
        
        End Function
        
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchByQuery(ByVal qry As SubSonic.Query) As TopicsCollection 
        
            Dim coll As TopicsCollection = New TopicsCollection()
            coll.LoadAndCloseReader(qry.ExecuteReader())
            Return coll
        
        End Function
        <DataObjectMethod(DataObjectMethodType.Delete, True)> Public Function Delete(ByVal Topicid As Object) as Boolean
        
            Return (Topics.Delete(Topicid) = 1)
        
        End Function
        <DataObjectMethod(DataObjectMethodType.Delete, False)> Public Function Destroy(ByVal Topicid As Object) as Boolean
        
            Return (Topics.Destroy(Topicid) = 1)
        
        End Function
        
    	
	    ''' <summary>
	    ''' Inserts a record, can be used with the Object Data Source
	    ''' </summary>
        <DataObjectMethod(DataObjectMethodType.Insert, True)> Public Sub Insert(ByVal Topic As String,ByVal Description As String,ByVal Section As Boolean,ByVal Weight As Integer,ByVal Locked As Boolean,ByVal Visible As Boolean,ByVal Moderatorkey As Nullable(Of Guid))
	   
		    Dim item As Topics = New Topics()
		    
            item.Topic = Topic
            
            item.Description = Description
            
            item.Section = Section
            
            item.Weight = Weight
            
            item.Locked = Locked
            
            item.Visible = Visible
            
            item.Moderatorkey = Moderatorkey
            
	    
		    item.Save(UserName)
	   
	   End Sub
    	
	    ''' <summary>
	    ''' Updates a record, can be used with the Object Data Source
	    ''' </summary>
        <DataObjectMethod(DataObjectMethodType.Update, True)> Public Sub Update(ByVal Topicid As Integer,ByVal Topic As String,ByVal Description As String,ByVal Section As Boolean,ByVal Weight As Integer,ByVal Locked As Boolean,ByVal Visible As Boolean,ByVal Moderatorkey As Nullable(Of Guid))
	    
		    Dim item As Topics = New Topics()
		    
				item.Topicid = Topicid
				
				item.Topic = Topic
				
				item.Description = Description
				
				item.Section = Section
				
				item.Weight = Weight
				
				item.Locked = Locked
				
				item.Visible = Visible
				
				item.Moderatorkey = Moderatorkey
				
		    item.MarkOld()
		    item.Save(UserName)
	    
	    End Sub
    End Class
End Namespace
